#include "SceneManagerTest.h"


SceneManagerTest::SceneManagerTest(void)
{
}


SceneManagerTest::~SceneManagerTest(void)
{
}

void SceneManagerTest::createScene(void)
{
	Ogre::Plane plane(Ogre::Vector3::UNIT_Y, -10);
	Ogre::MeshManager::getSingleton().createPlane("plane",Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
                        1500,1500,200,200,true,1,5,5,Ogre::Vector3::UNIT_Z);

	Ogre::Entity* ent = mSceneMgr->createEntity("planeEnt","plane");
	mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
	ent->setMaterialName("Examples/GrassFloor");
	

	Ogre::Light* light = mSceneMgr->createLight("Light1");

    light->setType(Ogre::Light::LT_DIRECTIONAL);

    light->setDirection(Ogre::Vector3(1,-1,0));

	//create a manual
	Ogre::ManualObject* manual = mSceneMgr->createManualObject("grass");

	manual->begin("Examples/GrassBlades", Ogre::RenderOperation::OT_TRIANGLE_LIST);


	//define vector position
	manual->position(5.0, 0.0, 0.0);   //first
	manual->textureCoord(1,1);
	manual->position(-5.0, 10.0, 0.0);
	manual->textureCoord(0,0);
	manual->position(-5.0, 0.0, 0.0);
	manual->textureCoord(0,1);
	manual->position(5.0, 10.0, 0.0);
	manual->textureCoord(1,0);

	manual->position(2.5, 0.0, 4.3);    //second
	manual->textureCoord(1,1);
	manual->position(-2.5, 10.0, -4.3);
	manual->textureCoord(0,0);
	manual->position(-2.0, 0.0, -4.3);
	manual->textureCoord(0,1);
	manual->position(2.5, 10.0, 4.3);
	manual->textureCoord(1,0);

	manual->position(2.5, 0.0, -4.3);    //third
	manual->textureCoord(1,1);
	manual->position(-2.5, 10.0, 4.3);
	manual->textureCoord(0,0);	
	manual->position(-2.0, 0.0, 4.3);
	manual->textureCoord(0,1);
	manual->position(2.5, 10.0, -4.3);
	manual->textureCoord(1,0);

	//define index
	manual->index(0);  //first trangle
	manual->index(1);
	manual->index(2);
	manual->index(0);
	manual->index(3);
	manual->index(1);

	manual->index(4);   //second
	manual->index(5);
	manual->index(6);
	manual->index(4);
	manual->index(7);
	manual->index(5);
	 
	manual->index(8);    //therd
	manual->index(9);
	manual->index(10);
	manual->index(8);
	manual->index(11);
	manual->index(9);

	manual->end();//important to end the manual define

	manual->convertToMesh("BladesOfGrass");//convert manual to mesh
	
	Ogre::StaticGeometry* field = mSceneMgr->createStaticGeometry("FieldOfGrass");

	for(int i=0;i<50;i++) 
	{
	  for(int j=0;j<50;j++) 
	  {
		  Ogre::Entity * ent = mSceneMgr->createEntity("BladesOfGrass");
		  field->addEntity(ent,Ogre::Vector3(i*3,-10,j*3));
	  }
	}

	field->build();

}


